package com.sgb.kjwl.viewmodel.self;

import android.content.Context;

import com.sgb.kjwl.api.APIManager;
import com.sgb.kjwl.api.NewAPIManager;
import com.sgb.kjwl.model.entity.AllFunction;
import com.sgb.kjwl.repository.SelfRepertory;
import com.sgb.kjwl.view.ui.activity.self.carMaster.EditeCarMoreInfoActivity;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.util.MToast;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class EditeCarMoreModel extends BaseViewModel {
    SelfRepertory repertory;
    EditeCarMoreInfoActivity mMoreInfoActivity;
    public EditeCarMoreModel(SelfRepertory repertory, EditeCarMoreInfoActivity mMoreInfoActivity) {
        this.repertory = repertory;
        this.mMoreInfoActivity = mMoreInfoActivity;
    }
    public void editHurdleHeightAndDumper(Context context,long id, String hurdleHeight, Integer dumper,String functionNos){
        DialogHelper.showProgressDialog(mMoreInfoActivity, null, "加载中", 0, true, null).setCanceledOnTouchOutside(false);
        Map map = new HashMap();
        map.put("id",id);
            map.put("hurdleHeight",hurdleHeight);
        if (dumper!=null){
            map.put("dumper",dumper);
        }
        map.put("functionNos",functionNos);
        APIManager.getInstance().getDriverAPI().editHurdleHeightAndDumper(map).enqueue(new Callback<BaseEntity>() {
            @Override
            public void onResponse(Call<BaseEntity> call, Response<BaseEntity> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null) return;
                if (response.body().getState().equals("ok")) {
                    mMoreInfoActivity.setData();
                }else {
                    MToast.showToast(context,"保存失败");
                }
            }

            @Override
            public void onFailure(Call<BaseEntity> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
                MToast.showToast(context,"保存失败");
            }
        });
    }
    public void getCarFuncation(){
        NewAPIManager.getInstance().getLogisticsAPI().getCarFunction02().enqueue(new Callback<BaseEntity<List<AllFunction>>>() {
            @Override
            public void onResponse(Call<BaseEntity<List<AllFunction>>> call, Response<BaseEntity<List<AllFunction>>> response) {
                if (response.body() == null) return;
                mMoreInfoActivity.setMyCarList(response.body().getData());
            }
            @Override
            public void onFailure(Call<BaseEntity<List<AllFunction>>> call, Throwable t) {

            }
        });
    }
}
